package com.heng.LockSupportDemo;

import java.util.concurrent.TimeUnit;
//异常情况
/**
 * 如果我们使用wait和notify必须包在syn同步代码块里
 * */
public class LockSupportDemo2 {
    public static void main(String[] args) {
        Object o = new Object();
        new Thread(() -> {
//            synchronized (o){
                System.out.println(Thread.currentThread().getName()+"\t---come in");
                try{
                    o.wait();
                }catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName()+"\t---被唤醒");
//            }
        },"t1").start();

        try {
            TimeUnit.MILLISECONDS.sleep(10);
        }catch (InterruptedException e) {
            e.printStackTrace();
        }
        
        new Thread(() -> {
//            synchronized (o) {
                o.notify();
                System.out.println(Thread.currentThread().getName()+"\t---发出通知");
//            }
        },"t2").start();
    }
}
